<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0,minimum-scale=1.0">
    <title>车辆调度</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0,minimum-scale=1.0">
    <link rel="stylesheet" href="../plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="../plugins/layui/css/myPage.css">
</head>
<body class="layui-layout-body">


<blockquote class="layui-elem-quote"  >
    <div class=" layui-form" >
        <div class="layui-form-item"  >


            <div class="layui-input-inline" style="width:10%">
                <select name="" lay-verify="required" id="khSearchKind" lay-filter="khSearchKind" >
                    <option value="">客户搜索类型</option>
                    <option value="khjc">客户简称</option>
                    <option value="khzjm">助记码</option>
                </select>

                <select name="" lay-filter="dingdan" id="ydSearchKind" >
                    <option value="">运单搜索类型</option>
                    <option value="ylzl">运力载量</option>
                    <option value="ydzt">运单状态</option>
                    <option value="ydh">运单号</option>
                </select>
            </div>
            <div class="layui-input-inline" id = "searchContentCon">
                <select   class="layui-input" id="khSearchContent" lay-search> <option value="">请选择</option></select>

                <!--<div id="ydh" style="display: none" ><select   class="layui-input"  id="ydhSearchContent" lay-search><option value="">请选择</option></select></div>-->
                <!--<div id="ydzt"  >-->
                <!--<select name="" lay-verify="required" id="ddSearchContent">-->
                <!--<option value=""></option>-->
                <!--<option value="待调度">待调度</option>-->
                <!--<option value="待发车">待发车</option>-->
                <!--<option value="已发车">已发车</option>-->
                <!--<option value="审核中">审核中</option>-->
                <!--</select>-->
                <!--</div>-->
                <div id = "ydSearchContentCon">
                <select class="layui-input" id="ydSearchContent" lay-search> <option value="">请选择</option></select>
                </div>
            </div>



            <div class="layui-input-inline" style="width: 10%">
                <select name="city"  id="xlSearchKind" lay-filter="xlSearchKind" >
                    <option value="">线路搜索类型</option>
                    <option value="xlmc">线路名称</option>
                    <option value="xlzjm">助记码</option>
                </select>
                <select name="city" lay-verify="required" id="qySearchKind" lay-filter="qySearchKind">
                    <option value="">区域搜索类型</option>
                    <option value="qymc">区域名称</option>
                    <option value="qyzjm">助记码</option>
                </select>
            </div>

            <div class="layui-input-inline">
                <select   class="layui-input" id="xlSearchContent" lay-search> <option value="">请选择</option></select>
                <select   class="layui-input" id="qySearchContent" lay-search> <option value="">请选择</option></select>

            </div>



            <div class="layui-input-inline" style="width: 110px">
                <label class="layui-form-label" style="margin-left: -25px">发车起始日期</label>
                <label class="layui-form-label" style="margin-left: -25px">发车结束日期</label>
            </div>
            <div class="layui-input-inline" style="width:10%">
                <input type="text"  class="layui-input"   id="searchQsrqContent">
                <input type="text"  class="layui-input" id="searchJsrqContent">
            </div>

            <div class="layui-input-inline" style="width: 10%">
                <select name="car"  id="clSearchKind" lay-filter="clSearchKind" >
                    <option value="">车辆搜索类型</option>
                    <option value="cph">车牌号</option>
                    <option value="jsyxm">司机姓名</option>
                    <option value="cllx">类型</option>
                </select>
            </div>

            <div class="layui-input-inline">
                <select   class="layui-input" id="clSearchContent" lay-search> <option value="">请选择</option></select>
            </div>


            <div class="layui-input-inline" style="width: 3%">
                <button class="layui-btn layui-btn-normal" id="search">点击搜索</button>
                <button type="button" class="layui-btn layui-btn-normal" id="all">显示全部</button>
            </div>


        </div>
    </div>
</blockquote>
<div class="layui-row">
    <div class="layui-col-xs12">



        <script type="text/html" id="opera">

            {{#  if(d.ydzt == '待调度'){ }}
            {{#  if( getQueryVariable("R") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled lay-event="detail">查看</button>
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="startcar">发车</button>
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled lay-event="posterror">退回</button>
            {{# }else{ }}

            <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">查看</button>
            {{#  if( getQueryVariable("P") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="startcar">发车</button>
            {{# }else{ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled "  disabled lay-event="startcar">发车</button>
            {{# } }}
            {{#  if( getQueryVariable("B") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="posterror">退回</button>
            {{# }else{ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs  "   lay-event="posterror">退回</button>
            {{# } }}

            {{# } }}

            {{# }else if(d.ydzt == '待发车'){ }}
            {{#  if( getQueryVariable("R") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled lay-event="detail">查看</button>
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="startcar">发车</button>
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="posterror">退回</button>
            {{# }else{ }}

            <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">查看</button>
            {{#  if( getQueryVariable("P") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="startcar">发车</button>
            {{# }else{ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs  "   lay-event="startcar">发车</button>
            {{# } }}

            {{#  if( getQueryVariable("B") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="posterror">退回</button>
            {{# }else{ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs  layui-btn-disabled" disabled  lay-event="posterror">退回</button>
            {{# } }}

            {{# } }}
            {{# }else if(d.ydzt == '已发车'){ }}
            {{#  if( getQueryVariable("R") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled lay-event="detail">查看</button>
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="startcar">发车</button>
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="posterror">退回</button>
            {{# }else{ }}

            <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">查看</button>
            {{#  if( getQueryVariable("P") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="startcar">发车</button>
            {{# }else{ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled " disabled  lay-event="startcar">发车</button>
            {{# } }}

            {{#  if( getQueryVariable("B") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="posterror">退回</button>
            {{# }else{ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs  "   lay-event="posterror">退回</button>
            {{# } }}

            {{# } }}
            {{# }else if(d.ydzt.split('_')[1] == '审核中'){ }}
            {{#  if( getQueryVariable("R") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled lay-event="detail">查看</button>
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="startcar">发车</button>
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="posterror">退回</button>
            {{# }else{ }}

            <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">查看</button>
            {{#  if( getQueryVariable("P") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="startcar">发车</button>
            {{# }else{ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs  layui-btn-disabled"  disabled lay-event="startcar">发车</button>
            {{# } }}


            <button class="layui-btn layui-btn-normal layui-btn-xs "  lay-event="posterror">退回</button>


            {{# } }}
            {{# } }}


        </script>
        <table id="table" lay-filter="Table"></table>
        <div id="laypage"></div>
        <script type="text/html" id="selectTpl_type">
            {{d.cph}}
        </script>
        <script type="text/html" id="selectOrderType">
            {{d.leixing}}
        </script>
        <script type="text/html" id="ydztfix">
            {{# if(d.ydzt.indexOf('_') != -1){ }}
            {{d.ydzt.split('_')[1]}}
            {{#   }else{ }}
            {{d.ydzt }}
            {{# } }}
        </script>
        <!--<script type="text/html" id="fcrq">-->
        <!--{{# if(d.fcrq == ""){ }}-->
        <!--{{d.fcrq= d.ydrq}}-->
        <!--{{#   }else{ }}-->
        <!--{{  d.fcrq  }}-->
        <!--{{# } }}-->
        <!--</script>-->
        <script type="text/html" id="fcrq">
            {{# if(d.fcrq == ""){ }}
            {{d.fcrq= d.ydrq}}
            {{#   }else{ }}
            {{  d.fcrq  }}
            {{# } }}
        </script>
    </div>
</div>




<script src="../js/tools.js"></script>
<script src="../plugins/layui/layui.js"></script>
<script src="../js/autocomplete.js"></script>
<script src="../js/config.js"></script>
<script>
    //JavaScript代码区域
    layui.use(['form' ,'table','jquery','layer','element','laydate','laypage'], function(){
        var form = layui.form;
        var table = layui.table;
        var $ = layui.$;
        var element = layui.element;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var tableheight=  'full-200';
        var tablewidth = 90;
        var currentPage = 1;
        var cphData=[];
        var leixingData=[];
        var limitcount = 10;
        var curnum = 1;
        var laypage = layui.laypage;



        var tablehead = [[ //表头
            {type:'numbers', title: '序号',  align:'center'}
            ,{field: 'ydh', title: '运单号' ,align:'center',width:160}
            ,{field: 'ydzt',templet:'#ydztfix' ,title: '运单状态',align:'center',width:100}

            ,{field: 'khjc', title: '客户简称' ,  align:'center',width:100}

            ,{field: 'qymc', title: '区域名称' ,  align:'center',width:100}
            ,{field: 'ylzl', title: '运力载量' ,  align:'center',width:90}
            ,{field: 'xlmc', title: '线路名称' ,  align:'center'}
            ,{field: 'fcrq', title: '发车日期' ,templet:'#fcrq',align:'center' ,edit: 'text',event:'fcrq',width:120}

            ,{field:'cph',templet: '#selectTpl_type', title: '车牌号' ,align:'center',event: 'cph',width:150   }

            ,{field: 'jsyxm', title: '驾驶员' ,align:'center',width:85}
            ,{field: 'jsysj', title: '驾驶员手机' ,align:'center',width:75}
            ,{field: 'leixing', templet: '#selectOrderType',title: '类型' ,align:'center',event: 'leixing',width:80}
            ,{field: 'llcyje', title: '理论充油金额' ,align:'center',width:75}
            ,{ title:'操作', align:'center', toolbar: '#opera'}
        ]]

        var elemNull = {};
        // elemNull.value = "&nbsp";
        // elemNull.text = "&nbsp";
        // cphData[0] = elemNull;
        //获取类型Data

        var leixingArr = ['带货','放空','来回','套跑','公司配货'];
        $.each(leixingArr,function (i,e) {
            var elem = {};
            elem.value = e;
            elem.text = e;
            leixingData[i+1] = elem;
        })

        //获取 cphData
        $.ajax({
            url: contextPath+"/carlist",
            type: "GET",
            contentType:"application/json;charset=utf-8",
            dataType:"json",
            success: function(res) {
                // console.log(res.list);

                for(var i in res.list){

                    var elem = {};
                    elem.value = res.list[i].clid;
                    elem.text = res.list[i].cph;
                    cphData[i+1] = elem;

                }


            }

        });

        //搜索的运单状态还是运单号

        form.on('select(dingdan)',function (data) {
            if(data.value == "ydh"){
                $("#ydSearchContent").empty();
                $("#ydSearchContentCon").remove();
                $("#searchContentCon").append("<div id='ydSearchContentCon'><input id=\"ydSearchContent\" class=\"ym-qatitle layui-input \" placeholder=\"模糊匹配\" autocomplete=\"off\"/></div> ");
                $.ajax({
                    url: contextPath+"/waybilllist/dd",
                    type: "GET",
                    contentType:"application/json;charset=utf-8",
                    dataType:"json",
                    success: function(res) {
                        var countriesArray =[]
                        console.log(res.list)
                        for(var i in res.list){

                            countriesArray.push({data:i,value:res.list[i].ydh})

                        }
                        $('#ydSearchContent').autocomplete({
                            lookup: countriesArray
                        });

                    }
                });
            }else if(data.value == "ydzt"){
                $("#ydSearchContent").empty();
                $("#ydSearchContentCon").remove();
                $("#searchContentCon").append(" <div id=\"ydSearchContentCon\">\n" +
                    "                    <select class=\"layui-input\" id=\"ydSearchContent\" lay-search> <option value=\"\">请选择</option></select>\n" +
                    "                </div>");
                var option = "<option value=\"待调度\">待调度</option>\n" +
                    "                        <option value=\"待发车\">待发车</option>" +
                    "                        <option value=\"已发车\">已发车</option>" +
                    "                        <option value=\"审核中\">审核中</option>"
                $("#ydSearchContent").append(option);
                form.render('select');
            }else if(data.value == "ylzl"){

                $("#ydSearchContent").empty();
                $("#ydSearchContentCon").remove();
                $("#searchContentCon").append(" <div id=\"ydSearchContentCon\">\n" +
                    "                    <select class=\"layui-input\" id=\"ydSearchContent\" lay-search> <option value=\"\">请选择</option></select>\n" +
                    "                </div>");
                var option =
                    "<option value=\"30\">30</option>" +
                    "<option value=\"20\">20</option>" +
                    "<option value=\"14\">14</option>" +

                    "<option value=\"7\">7</option>"+
                    "<option value=\"4\">4</option>"+
                    "<option value=\"2\">2</option>";

                $("#ydSearchContent").append(option);
                form.render('select');
            }
        });



        //  渲染搜索 select
        yewuSearch(form,$);
        form.on("select(clSearchKind)",function (data) {
            console.log("cl")
            if(data.value == "cph" ){
                console.log("chepaihao")
                $("#clSearchContent").empty();
                $.ajax({
                    url: contextPath+"/carlist",
                    type: "GET",
                    contentType:"application/json;charset=utf-8",
                    dataType:"json",
                    success: function(res) {
                        $("#clSearchContent").append("<option value=''>请选择</option>");
                        for(var i in res.list){
                            var option = "<option value='"+ res.list[i].cph+ "'>"+res.list[i].cph+"</option>";
                            $("#clSearchContent").append(option);
                        };
                        form.render('select');
                    }
                });
            }else if(data.value == "jsyxm" ){
                console.log("jsyxm")
                $("#clSearchContent").empty();
                $.ajax({
                    url: contextPath+"/drivername",
                    type: "GET",
                    contentType:"application/json;charset=utf-8",
                    dataType:"json",
                    success: function(res) {
                        $("#clSearchContent").append("<option value=''>请选择</option>");
                        for(var i in res.list){
                            var option = "<option value='"+ res.list[i][0]+"'>"+res.list[i][0]+"</option>";
                            $("#clSearchContent").append(option);
                        };
                        form.render('select');
                    }
                });
            }
            else if(data.value == "cllx" ){
                console.log("cllx")
                $("#clSearchContent").empty();
                $("#clSearchContent").append("<option value=''>请选择</option>");
                var option = "<option value=带货>带货</option>" +
                    "<option value=放空>放空</option>" +
                    "<option value=来回>来回</option>" +
                    "<option value=套跑>套跑</option>" +
                    "<option value=公司配货>公司配货</option>";
                $("#clSearchContent").append(option);
                form.render('select');

            }else{
                $("#clSearchContent").empty();
            }

        });

        //执行一个laydate实例
        laydate.render({
            elem: '#ydrq' //指定元素
            ,format:'yyyy-MM-dd'
            ,theme:'#0099FF'

        });
        laydate.render({
            elem: '#searchQsrqContent' //指定元素
            ,format:'yyyy-MM-dd'
            ,theme:'#0099FF'
        });
        laydate.render({
            elem: '#searchJsrqContent' //指定元素
            ,format:'yyyy-MM-dd'
            ,theme:'#0099FF'

        });



//请求车牌号

        vehicleSchedul(curnum, limitcount);
        function vehicleSchedul(start,limitsize) {
            layui.use(['table','laypage','laydate'], function(){
                var table = layui.table,
                    laypage = layui.laypage;
                table.render({
                    url: contextPath + "waybill?bd=dd&pageNum="+start+"&pageSize="+limitsize,
                    elem: '#table',
                    height: tableheight,
                    page: false,
                    id: 'table',
                    cellMinWidth: tablewidth,
                    cols: tablehead,
                    done: function (res, curr,count) {
                        laypage.render({
                            elem: 'laypage'
                            , count: count
                            , curr: curnum
                            , limit: limitcount
                            , layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
                            , jump: function (obj, first) {
                                if (!first) {
                                    curnum = obj.curr;
                                    limitcount = obj.limit;
                                    //console.log("curnum"+curnum);
                                    //console.log("limitcount"+limitcount);
                                    //layer.msg(curnum+"-"+limitcount);
                                    vehicleSchedul(curnum, limitcount);
                                }
                            }
                        });
                    }
                });
            });
        }


        function vehicleSchedulsearch(start,limitsize) {
            layui.use(['table','laypage','laydate'], function(){
                var table = layui.table,
                    laypage = layui.laypage;
                table.render({
                    url: contextPath + "waybill?bd=dd&pageNum="+start+"&pageSize="+limitsize+"&"+$("#khSearchKind").val()+"="+$("#khSearchContent").val()+"&"+$("#xlSearchKind").val()+"="+$("#xlSearchContent").val()+"&"+$("#qySearchKind").val()+"="+$("#qySearchContent").val()+"&"+$("#clSearchKind").val()+"="+$("#clSearchContent").val()+"&"+$("#ydSearchKind").val()+"="+$("#ydSearchContent").val()+"&qsrq="+$("#searchQsrqContent").val()+"&"+"jsrq="+$("#searchJsrqContent").val(),
                    dataType: "object",
                    elem: '#table',
                    height: tableheight,
                    page: false,
                    id: 'table',
                    cellMinWidth: tablewidth,
                    cols: tablehead,
                    done: function (res, curr,count) {
                        laypage.render({
                            elem: 'laypage'
                            , count: count
                            , curr: start
                            , limit: limitsize
                            , layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
                            , jump: function (obj, first) {
                                if (!first) {
                                    curnum = obj.curr;
                                    limitcount = obj.limit;
                                    // console.log("curnum"+curnum);
                                    // console.log("limitcount"+limitcount);
                                    //layer.msg(curnum+"-"+limitcount);
                                    vehicleSchedulsearch(curnum, limitcount);
                                }
                            }
                        });
                    }
                });
            });
        }


        //刷新table实例
        $("#all").on('click',function () {
            curnum =1;
            vehicleSchedul(curnum, limitcount);
        });

//监听单元格编辑
//         console.log($("tr"))
        table.on('edit(Table)',function (obj) {
            var s = obj.data.fcrq;
            var reg = /^([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8])))$/;

            s = s.replace(/^\s+|\s+$/g, "");
            console.log(reg.test(s))
            if (!reg.test(s)) {
                console.log(s)
                layer.msg("日期格式不正确！");
                console.log(s)

            }else {
                // console.log(s.text)
                if (s.text != "") {
                    $.ajax({
                        url: contextPath + "/waybill/fcrq",
                        type: "PUT",
                        contentType: "application/json;charset=utf-8",
                        dataType: "json",
                        data: JSON.stringify(obj.data),
                        success: function (res) {
                            // obj.data.fcrq = s.text;
                            // obj.update(obj.data);
                        }

                    });

                }
            }
        });
//监听表格

        table.on('tool(Table)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值
            if(obj.data.ydzt == "订单_审核中"){
                obj.data.ydzt = "审核中";
                obj.data.oldydzt="订单_审核中"
            }else if(obj.data.ydzt == "调度_审核中"){
                obj.data.ydzt = "审核中";
                obj.data.oldydzt="调度_审核中"
            }

            if(layEvent === 'detail'){
                // console.log(data);
                layer.open({
                    // cancel: function(index, layero){
                    //     var faIndex = index;
                    //     layer.confirm('确定要关闭么?未保存的信息将会丢失!', {icon: 3, title:'提示'}, function(index){
                    //         //do something
                    //         layer.close(index);
                    //         layer.close(faIndex);
                    //     });
                    //     return false
                    // },
                    type: 2,
                    title: '查看运单信息',
                    maxmin: true,
                    //点击遮罩关闭层
                    shadeClose:false,
                    area : ['80%' , '60%'],
                    content: ['./lookVeSch.html','no'],
                    success:function(layero,index){
                        console.log(data);
                        var body = layer.getChildFrame('body',index);

                        for(var i in data){
                            body.contents().find("[name='"+i+"']").val(eval("data."+i));
                        }
                    },
                    end:function(){

                    }
                });
            } else if(layEvent === 'delete'){
                layer.confirm('确定删除？', function(index){
                    obj.del(); //删除对应行（tr）的DOM结构
                    layer.close(index);
                    //向服务端发送删除指令
                    $.ajax({
                        url: contextPath+"/waybill/"+data.ydid,
                        type: "DELETE",
                        contentType:"application/json;charset=utf-8",
                        dataType:"json",
                        success: function(res) {
                            layer.msg(res.message);
                            vehicleSchedulsearch(curnum, limitcount);
                        }
                    });
                });
            }else if(layEvent === 'startcar'){
                var startcardata = {};
                startcardata.ydid = data.ydid;
                $.ajax({
                    url: contextPath+"/waybill/"+data.ydid,
                    type: "PUT",
                    data:JSON.stringify(data),
                    contentType:"application/json;charset=utf-8",
                    dataType:"json",
                    success: function(res) {
                        layer.msg(res.message);
                        obj.update({
                            ydzt: '已发车'
                        });
                        // vehicleSchedulsearch(curnum, limitcount);
                    }
                });

            }else if(layEvent === 'posterror') {
                layer.open({
                    cancel: function (index, layero) {
                        var faIndex = index;
                        layer.confirm('确定要关闭么?未保存的信息将会丢失!', {icon: 3, title: '提示'}, function (index) {
                            //do something
                            layer.close(index);
                            layer.close(faIndex);
                        });
                        return false
                    },
                    type: 2,
                    title: '退回',
                    maxmin: true,
                    //点击遮罩关闭层
                    area: ['80%', '80%'],
                    content: ['./postError.html'],
                    success: function (layero, index) {

                        // console.log(data);

                        if(obj.data.ydzt=="待调度"){//待调度退回
                            var body = layer.getChildFrame('body', index);
                            data.comefrom = "ddd";
                            for (var i in data) {
                                body.contents().find("[name='" + i + "']").val(eval("data." + i));
                            }
                        }else if(obj.data.ydzt=="已发车"){//待发车退回
                            var body = layer.getChildFrame('body', index);
                            data.comefrom = "dd";
                            for (var i in data) {
                                body.contents().find("[name='" + i + "']").val(eval("data." + i));
                            }
                        }else if(obj.data.oldydzt=="订单_审核中"){//待调度退回
                            var body = layer.getChildFrame('body', index);
                            data.comefrom = "ddd";
                            for (var i in data) {
                                body.contents().find("[name='" + i + "']").val(eval("data." + i));
                            }
                        }else if(obj.data.oldydzt=="调度_审核中"){//待发车退回
                            var body = layer.getChildFrame('body', index);
                            data.comefrom = "dd";
                            for (var i in data) {
                                body.contents().find("[name='" + i + "']").val(eval("data." + i));
                            }
                        }

                    },
                    end: function () {
                        vehicleSchedulsearch(curnum, limitcount);
                    }
                });
            }
            else if(obj.event === 'cph') {
                if (getQueryVariable("U")=="true"){
                // console.log(obj);
                //渲染下拉列表
                    (function ($, doc, o, cph) {
                        var tk;
                        var obj;
                        var otd;
                        var callback;
                        o.show = function (h, e, c) {
                            callback = c;
                            var d = doc.getElementById('table_type_select');
                            if (d) {
                                d.remove();
                            }
                            otd = e;
                            var s = '<div id="table_type_select" class="table-select"><dl class="layui-anim layui-anim-downbit" style="padding: 0px;top: 0px">';
                            s += '<input is_input="1" id="table_type_select_input" value="' + cph + '" class="layui-input" type="text">';
                            s += '<dd lay-value="" >&nbsp</dd>';
                            for (var k in h.data) {

                                s += '<dd lay-value="' + h.data[k].value + '" >' + h.data[k].text + '</dd>';

                            }
                            s += '</dl></div>';
                            otd.innerHTML = s + otd.innerHTML;
                            obj = doc.getElementById('table_type_select');
                            //console.log($(obj));
                            obj.onmouseout = function () {
                                tk = 1;
                                setTimeout(function () {
                                    if (tk) {
                                        if (obj) {
                                            ke = 0;
                                            obj.remove();
                                            callback({value: "", text: ""});
                                        }
                                    }
                                }, 200);
                            }
                            obj.onmouseover = function () {
                                tk = 0;
                            }
                            obj.addEventListener('click', function (e) {

                                if ($(e.srcElement).attr('is_input')) {
                                    $("#table_type_select_input").focus(); //聚焦
                                    e.stopImmediatePropagation(); //阻止冒泡
                                    $("#table_type_select_input").bind("input propertychange", function () { //获取输入内容
                                        $("#table_type_select dd").each(function (i, elem) {
                                            if ($(this).html().indexOf($("#table_type_select_input").val()) == -1) {
                                                // console.log(i + $(this).html() );
                                                $(this).css("display", "none");
                                            } else {
                                                $(this).css("display", "");
                                            }
                                        });

                                    });
                                } else {
                                    var value = $(e.srcElement).attr('lay-value');
                                    var text = e.srcElement.innerHTML;
                                    obj.remove();
                                    callback({value: value, text: text});
                                }
                            });
                        }
                    })($, document, window.type_select = {}, obj.data.cph);

                if (obj.data.ydzt != "已发车") {//判断是否发车
                    type_select.show({
                        //设置当前选择的id
                        value: obj.data.cph,
                        //下拉选择数据
                        data: cphData
                    }, this, function (e) {
                        //回调函数 返回结果

                        var objData = {};
                        objData.clid = e.value;
                        objData.ydid = data.ydid;

                        // console.log(objData);
                        // console.log(e.text)
                        if (e.text != "") {
                            $.ajax({
                                url: contextPath + "/waybill/cph",
                                type: "PUT",
                                contentType: "application/json;charset=utf-8",
                                dataType: "json",
                                data: JSON.stringify(objData),
                                success: function (res) {
                                    // console.log(res.list)
                                    // if(e.text="&nbsp"){
                                    //     obj.data.cph = ""
                                    // }else {
                                    obj.data.cph = e.text;
                                    // }
                                    if (res.list.jsyxm != null) {
                                        obj.data.jsyxm = res.list.jsyxm
                                    } else {
                                        obj.data.jsyxm = ""
                                    }
                                    if (res.list.jsysj != null) {
                                        obj.data.jsysj = res.list.jsysj
                                    } else {
                                        obj.data.jsysj = ""
                                    }
                                    if (res.list.ydzt != null) {
                                        obj.data.ydzt = res.list.ydzt
                                    }
                                    obj.update(obj.data);
                                    if (res.list.ydzt == "待发车") {
                                        vehicleSchedulsearch(curnum, limitcount);

                                    }


                                }
                            });
                        }


                        form.render();

                    });
                } else {
                    alert("本单已经发车!")
                }
            }
            } else if(obj.event === 'leixing') {
                if (getQueryVariable("U")=="true"){
                // console.log(obj);
                //渲染下拉列表
                    (function ($, doc, o) {
                        var tk;
                        var obj;
                        var otd;
                        var callback;
                        o.show = function (h, e, c) {
                            callback = c;
                            var d = doc.getElementById('table_type_select2');
                            if (d) {
                                d.remove();
                            }
                            otd = e;
                            var s = '<div id="table_type_select2" class="table-select"><dl class="layui-anim layui-anim-downbit" style="padding: 0px;top: 0px">';
                            //   s+= '<input is_input="1" id="table_type_select_input"  class="layui-input" type="text">';
                            s += '<dd lay-value="" >&nbsp</dd>';
                            for (var k in h.data) {

                                s += '<dd lay-value="' + h.data[k].value + '" >' + h.data[k].text + '</dd>';

                            }
                            s += '</dl></div>';
                            otd.innerHTML = s + otd.innerHTML;
                            obj = doc.getElementById('table_type_select2');
                            //console.log($(obj));
                            obj.onmouseout = function () {
                                tk = 1;
                                setTimeout(function () {
                                    if (tk) {
                                        if (obj) {
                                            ke = 0;
                                            obj.remove();
                                            callback({value: "", text: ""});
                                        }
                                    }
                                }, 200);
                            }
                            obj.onmouseover = function () {
                                tk = 0;
                            }
                            obj.addEventListener('click', function (e) {

                                var value = $(e.srcElement).attr('lay-value');
                                var text = e.srcElement.innerHTML;
                                obj.remove();
                                callback({value: value, text: text});

                            });
                        }
                    })($, document, window.type_select = {});

                if (obj.data.ydzt != "已发车") {//判断是否发车
                    type_select.show({
                        //设置当前选择的id
                        value: obj.data.leixing,
                        //下拉选择数据
                        data: leixingData
                    }, this, function (e) {
                        //回调函数 返回结果

                        var objData = {};
                        objData.leixing = e.value;
                        objData.ydid = data.ydid;

                        // console.log(objData);
                        if (e.text != "") {
                            $.ajax({
                                url: contextPath + "/waybill/type",
                                type: "PUT",
                                contentType: "application/json;charset=utf-8",
                                dataType: "json",
                                data: JSON.stringify(objData),
                                success: function (res) {
                                    obj.data.leixing = e.text;
                                    // console.log(res.list)

                                    // layer.msg(res.message);
                                    if (res.list.ydzt != null) {
                                        obj.data.ydzt = res.list.ydzt
                                    }
                                    obj.update(obj.data);
                                    if (res.list.ydzt == "待发车") {
                                        vehicleSchedulsearch(curnum, limitcount);

                                    }

                                }
                            });
                        }


                        form.render();
                    });
                } else {
                    alert("本单已经发车!")
                }
            }
            }else if(obj.event == "fcrq"){
                console.log("fcrq")
                if(obj.data.ydzt == "已发车"){
                    if(event.button==0){
                        alert("本单已经发车!")
                    }
                }
            }
        });





//搜索
        $("#search").on('click',function () {
            if($("#searchQsrqContent").val() != "" && $("#searchJsrqContent").val() != ""){
                if(!checkEndTime($("#searchQsrqContent").val(),$("#searchJsrqContent").val())){
                    layer.msg("起始日期大于结束日期!");
                }else {
                    curnum = 1;
                    layui.use(['table','laypage','laydate'], function(){
                        var table = layui.table,
                            laypage = layui.laypage;
                        table.render({
                            url: contextPath + "waybill?bd=dd&pageNum="+curnum+"&pageSize="+limitcount+"&"+$("#khSearchKind").val()+"="+$("#khSearchContent").val()+"&"+$("#xlSearchKind").val()+"="+$("#xlSearchContent").val()+"&"+$("#qySearchKind").val()+"="+$("#qySearchContent").val()+"&"+$("#clSearchKind").val()+"="+$("#clSearchContent").val()+"&"+$("#ydSearchKind").val()+"="+$("#ydSearchContent").val()+"&qsrq="+$("#searchQsrqContent").val()+"&"+"jsrq="+$("#searchJsrqContent").val(),
                            dataType: "object",
                            elem: '#table',
                            height: tableheight,
                            page: false,
                            id: 'table',
                            cellMinWidth: tablewidth,
                            cols: tablehead,
                            done: function (res, curr,count) {
                                laypage.render({
                                    elem: 'laypage'
                                    , count: count
                                    , curr: curnum
                                    , limit: limitcount
                                    , layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
                                    , jump: function (obj, first) {
                                        if (!first) {
                                             curnum = obj.curr;
                                             limitcount = obj.limit;
                                            // console.log("curnum"+curnum1);
                                            // console.log("limitcount"+limitcount1);
                                            //layer.msg(curnum+"-"+limitcount);
                                            vehicleSchedulsearch(curnum, limitcount);
                                        }
                                    }
                                });
                            }
                        });
                    });
                }
            } else if($("#searchQsrqContent").val() != "" && $("#searchJsrqContent").val() == ""){
                layer.msg("结束日期不能为空！");
            }else if($("#searchQsrqContent").val() == "" && $("#searchJsrqContent").val() != ""){
                layer.msg("起始日期不能为空！");
            }else {
                curnum = 1;
                layui.use(['table','laypage','laydate'], function(){
                    var table = layui.table,
                        laypage = layui.laypage;
                    table.render({
                        url: contextPath + "waybill?bd=dd&pageNum="+curnum+"&pageSize="+limitcount+"&"+$("#khSearchKind").val()+"="+$("#khSearchContent").val()+"&"+$("#xlSearchKind").val()+"="+$("#xlSearchContent").val()+"&"+$("#qySearchKind").val()+"="+$("#qySearchContent").val()+"&"+$("#clSearchKind").val()+"="+$("#clSearchContent").val()+"&"+$("#ydSearchKind").val()+"="+$("#ydSearchContent").val()+"&qsrq="+$("#searchQsrqContent").val()+"&"+"jsrq="+$("#searchJsrqContent").val(),
                        dataType: "object",
                        elem: '#table',
                        height: tableheight,
                        page: false,
                        id: 'table',
                        cellMinWidth: tablewidth,
                        cols: tablehead,
                        done: function (res, curr,count) {
                            laypage.render({
                                elem: 'laypage'
                                , count: count
                                , curr: curnum
                                , limit: limitcount
                                , layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
                                , jump: function (obj, first) {
                                    if (!first) {
                                        curnum = obj.curr;
                                        limitcount = obj.limit;
                                        //console.log("curnum"+curnum);
                                        //console.log("limitcount"+limitcount);
                                        //layer.msg(curnum+"-"+limitcount);
                                        vehicleSchedulsearch(curnum, limitcount);
                                    }
                                }
                            });
                        }
                    });
                });
            }
        });


    });





</script>
<script type="text/javascript">

    //处理键盘事件 禁止后退键（Backspace）密码或单行、多行文本框除外
    function banBackSpace(e){
        var ev = e || window.event;//获取event对象
        var obj = ev.target || ev.srcElement;//获取事件源

        var t = obj.type || obj.getAttribute('type');//获取事件源类型

//获取作为判断条件的事件类型
        var vReadOnly = obj.getAttribute('readonly');
        var vEnabled = obj.getAttribute('enabled');
//处理null值情况
        vReadOnly = (vReadOnly == null) ? false : vReadOnly;
        vEnabled = (vEnabled == null) ? true : vEnabled;

//当敲Backspace键时，事件源类型为密码或单行、多行文本的，
//并且readonly属性为true或enabled属性为false的，则退格键失效
        var flag1=(ev.keyCode == 8 && (t=="password" || t=="text" || t=="textarea")
            && (vReadOnly==true || vEnabled!=true))?true:false;

//当敲Backspace键时，事件源类型非密码或单行、多行文本的，则退格键失效
        var flag2=(ev.keyCode == 8 && t != "password" && t != "text" && t != "textarea")
            ?true:false;

//判断
        if(flag2){
            return false;
        }
        if(flag1){
            return false;
        }
    }

    //禁止后退键 作用于Firefox、Opera
    // document.onkeypress=banBackSpace;
    //禁止后退键 作用于IE、Chrome
    document.onkeydown=banBackSpace;

</script>

</body>
</html>